﻿namespace CatClient.Message.Internals
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Text;

    [Obsolete]
    public class MessageId
    {
        private readonly string _mDomain;
        private readonly int _mIndex;
        private readonly string _mIpAddressInHex;
        private readonly long _mTimestamp;

        internal MessageId(string domain, string ipAddressInHex, long timestamp, int index)
        {
            this._mDomain = domain;
            this._mIpAddressInHex = ipAddressInHex;
            this._mTimestamp = timestamp;
            this._mIndex = index;
        }

        public static MessageId Parse(string messageId)
        {
            string str2;
            char[] separator = new char[] { '-' };
            IList<string> list = messageId.Split(separator);
            int count = list.Count;
            if (count < 4)
            {
                throw new Exception("Invalid message id format: " + messageId);
            }
            string ipAddressInHex = list[count - 3];
            long timestamp = long.Parse(list[count - 2], NumberStyles.Integer);
            int index = int.Parse(list[count - 1]);
            if (count > 4)
            {
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < (count - 3); i++)
                {
                    if (i > 0)
                    {
                        builder.Append('-');
                    }
                    builder.Append(list[i]);
                }
                str2 = builder.ToString();
            }
            else
            {
                str2 = list[0];
            }
            return new MessageId(str2, ipAddressInHex, timestamp, index);
        }

        public override string ToString()
        {
            StringBuilder builder1 = new StringBuilder(this._mDomain.Length + 0x20);
            builder1.Append(this._mDomain);
            builder1.Append('-');
            builder1.Append(this._mIpAddressInHex);
            builder1.Append('-');
            builder1.Append(this._mTimestamp);
            builder1.Append('-');
            builder1.Append(this._mIndex);
            return builder1.ToString();
        }

        public string Domain =>
            this._mDomain;

        public int Index =>
            this._mIndex;

        public string IpAddressInHex =>
            this._mIpAddressInHex;

        public long Timestamp =>
            this._mTimestamp;
    }
}

